<template>
  <div>
    <Row class="search-info-style">
<!--      <Col span="6">-->
<!--        <span>&nbsp;姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名&nbsp;：</span>-->
<!--        <Input v-model="searchInfo.name" placeholder="姓名" style="width:70%" />-->
<!--      </Col>-->
      <Col span="6">
        <span>证件号码：</span>
        <Input v-model="searchInfo.card_no" placeholder="证件号码" style="width:70%" />
      </Col>
      <Col style="float:right" pull="1">
        <Button class="new-btn-sty" @click="findtime()"><Icon type="ios-search" />搜索</Button>
<!--        <Button v-if="this.$store.state.user.severUserInfo.company_grade === '5'" class="new-btn-sty" @click="add()"><Icon type="md-add" />添加成员</Button>-->
      </Col>
    </Row>
    <Table border :columns="columns1" :data="data1">
      <template slot-scope="{row}" slot="CPBI008">
        <span :value="item.TYPECODE" v-for="item in dictList[0]" v-bind:key="item.TYPECODE" v-if="row.CPBI008 == item.TYPECODE">{{item.TYPENAME}}</span>
      </template>
    </Table>
    <Row v-if="loadData == true">
      <Col class="demo-spin-col" span="8" offset="8">
        <Spin fix>
          <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
          <div>数据正在加载</div>
        </Spin>
      </Col>
    </Row>
<!--    <Page class="page_style" :total="totalnum" :current="currentPageNo"-->
<!--          :page-size="currentPageSize" @on-change="changePageNo" show-total  show-sizer @on-page-size-change="size"/>-->
    <Modal v-model="modalEdit" title="确认操作" width="700" cancel-text="关闭"
           @on-ok="ok111()" @on-cancel="modalEdit1=false" ok-text="确定">
      <div style="font-size: 1rem; text-align: center;">确认将{{name}}（证件号码：{{card_no}}）录入本社区！</div>
    </Modal>
  </div>
</template>
<script>
import { findPersonnelList, getTypeNameList, addPersonneInfo } from '@/api/eventlist'
export default {
  data () {
    return {
      currentPageNo: 1,
      currentPageSize: 10,
      totalnum: 0,
      name: '',
      card_no: '',
      modalEdit: false,
      loadData: false,
      searchInfo: {},
      paramData: {},
      dictList: [],
      data1: [],
      columns1: [
        { title: '序号', type: 'index', width: 80, align: 'center' },
        { title: '姓名', key: 'CPBI003', width: 100, align: 'center' },
        { title: '性别', key: 'sex', width: 100, align: 'center' },
        { title: '年龄', key: 'age', width: 100, align: 'center' },
        { title: '身份证号', key: 'CPBI002', width: 300, align: 'center' },
        { title: '政治面貌', slot: 'CPBI008', width: 200, align: 'center' },
        { title: '联系方式', key: 'CPBI013', width: 200, align: 'center' },
        {
          title: '操作',
          key: 'action',
          align: 'center',
          className: 'nopadding',
          minWidth: 200,
          render: (h, params) => {
            let temp = []
            temp.push(
              h('Button', {
                props: {type: 'error', size: 'small'},
                style: {marginRight: '5px', backgroundColor: '#18B0FF', borderColor: '#18B0FF'},
                on: {
                  click: () => {
                    this.downLoad(params.row)
                  }
                }
              }, '录入')
            )
            return h('div', temp)
          }
        }
      ]
    }
  },
  methods: {
    init() {
      if (!this.searchInfo.card_no) {
        return
      }
      let param = {
        pageSize: this.currentPageSize,
        pageNo: this.currentPageNo,
        name: this.searchInfo.name,
        card_no: this.searchInfo.card_no
      }
      findPersonnelList(param).then(res =>{
        if (res.data.errcode === 0) {
          this.data1 = res.data.data.results
          this.totalnum = res.data.data.totalRecord
          this.loadData = false
        } else {
          this.$Notice.error({
            title: '获取人员列表失败',
            desc: res.data.errmsg
          })
          this.loadData = false
        }
      })
    },
    findtime() {
      this.init()
    },
    // 录入
    downLoad(item) {
      this.paramData = item
      this.modalEdit = true
      this.name = item.CPBI003
      this.card_no = item.CPBI002
    },
    ok111() {
      this.paramData.grade = this.$store.state.user.severUserInfo.company_grade
      addPersonneInfo(this.paramData).then(res => {
        if (res.data.errcode === 0) {
          this.$Notice.success({ title: '录入成功', desc: '' })
        } else {
          this.$Notice.error({
            title: '人员录入失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    size (pageSize) {
      this.currentPageSize = pageSize
      this.changePageNo()
    },
    changePageNo (pageNo) {
      this.currentPageNo = pageNo
      this.init()
    },
    getTypeName (id, index) {
      getTypeNameList({ typegroupcode: id }).then(res => {
        if (res.data.errcode === 0) {
          this.dictList[index] = res.data.data
        } else {
          this.$Notice.error({
            title: '获取字典列表失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    getDictList () {
      this.getTypeName('political', 0)
      // this.getTypeName('position', 1)
      // this.getTypeName('cpbi018', 2)
      // this.getTypeName('marriage', 3)
      // this.getTypeName('nation', 4)
      // this.getTypeName('incumbency', 5)
      // this.getTypeName('sp_status', 6)
      // this.getTypeName('degree', 7)
      // this.getTypeName('academic', 8)
      // this.getTypeName('lineal', 9)
      // this.getTypeName('pqoswt', 10)
      // this.getTypeName('train', 11)
      // this.getTypeName('examType', 12)
      // this.getTypeName('examresult', 13)
    },
  },
  mounted() {
    this.getDictList()
  }
}
</script>
<style>
  .search-info-style {
    margin: 10px;
  }
  .new-btn-sty {
    margin-right: 5px;
    color: #fff;
    background-color: #235CA7;
    border-color: #235CA7;
    font-weight: 500;
  }
  .item1{
    height: 42px;
    line-height: 40px;
  }
  .page_style {
    margin-top: 10px;
    text-align: right;
  }
</style>
